// pages/my/lc-detail/lc-detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordlist: [],
    info: {},
    page: 1,
    maxPage: 10,
    totalPages: 1,
    showbottom: false,
    bottomtext: '加载中...',
    rate: {},
    chaojishow: false,
    chaoji: getApp().globalData.source + "dialog/chaoji.png",
  },
  closePopUp: function() {
    var that = this;
    this.setData({
      chaojishow: !that.data.chaojishow
    })
  },
  withdraw: function() {
    wx.navigateTo({
      url: '../../listen_cash/listen_cash',
    })
  },
  getdata: function() {
    var vm = this
    var userIds = wx.getStorageSync("userId") === "" ? -1 : wx.getStorageSync("userId");
    var data = {
      userId: userIds,
      startPoint: vm.data.page,
      maxPage: 10,
      "type": 1
    }
    getApp().requestLoading(getApp().globalData.https + "orderResource/pkgRecord/" + userIds + "/1",
      "get", data, "加载中",
      function(res) {
        console.log(JSON.stringify(res))
        if (res.code == 0) {
          // <!--交易类型 0.充值，1.购买，2.提现，3.签到，4.助力，5.听时长，6.随机活动，7.邀请好友-- >
          var newdata = [];
          if (res.data.data.length < 10) {
            vm.setData({
              bottomtext: "没有更多数据",
              showbottom: true
            })
          }
          // for(var i=0;i<res.data.data.length;i++){
          //   if (res.data.data[i].payStatus != 0 && res.data.data[i].payStatus != 1 && res.data.data[i].payStatus != 2 && res.data.data[i].payStatus != 7){
          //     newdata.push(res.data.data[i])
          //   }
          // }
          vm.setData({
            recordlist: vm.data.recordlist.concat(res.data.data),
            totalPages: res.data.totalPages
          })
        }
      },
      function(res) {});
  },

  gohome: function () {
    wx.switchTab({
      url: '/pages/style/style',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var vm = this
    var showhomeicon = options.showhomeicon == "fx" ? true : ""; //判断是分享页进入还是小程序正常进入
    if (showhomeicon) {
      this.setData({
        showhomeicon: showhomeicon
      })
    }
    this.getdata()
    var data = {}
    var userIds = wx.getStorageSync("userId") === "" ? -1 : wx.getStorageSync("userId");
    getApp().request(getApp().globalData.https + "/orderResource/walletBalance/" + userIds,
      "get", data,
      function(res) {
        if (res.code == 0) {
          vm.setData({
            info: res.data,
          })
        }
      },
      function(res) {});


    getApp().request(getApp().globalData.https + "/orderResource/exchangeRate",
      "get", data,
      function(res) {
        if (res.code == 0) {
          var data = res.data.shift();
          console.log(JSON.stringify(data))
          vm.setData({
            rate: data
          })
        }
      },
      function(res) {});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    if (that.data.page < that.data.totalPages) {
      that.setData({
        page: that.data.page + 1
      })
      this.getdata()
    } else {
      that.setData({
        showbottom: true
      })
    }
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(e) {
    var that = this;
    var userIds = wx.getStorageSync("userId")
    return {
      path: "/pages/my/mydetail/mydetail?showhomeicon=fx",
      success(res) {
        console.log("success")
      },
      fail(e) {
        console.log("fail")
      },
      //分享完成
      complete() {
        console.log("complete")
      }
    }
  },

})